/*
 * IMGSplitter.cpp
 *
 *  Created on: 07.10.2013
 *      Author: dima
 */


#include "IMGSplitter.hpp"



namespace
{
  int const TANK_HEIGHT = 100;
  int const TANK_WIDTH  = 100;

  int const EXPLOSION_HEIGHT = 20;
  int const EXPLOSION_WIDTH = 20;

  int const EXPLOSION_TANK_HEIGHT = 120;
  int const EXPLOSION_TANK_WIDTH = 120;
}


Tanks::Resources::IMGSplitter &
Tanks::
Resources::
IMGSplitter::
getInstance()
{
  static IMGSplitter instance;
  return instance;
}


void
Tanks::
Resources::
IMGSplitter::
Split()
{
  std::vector<SDL_Rect> animation;

  animation.push_back(CreateRect(0, TANK_HEIGHT, TANK_WIDTH, TANK_HEIGHT));
  animation.push_back(CreateRect(TANK_WIDTH, TANK_HEIGHT, TANK_WIDTH, TANK_HEIGHT));
  animation.push_back(CreateRect(2*TANK_WIDTH, TANK_HEIGHT, TANK_WIDTH, TANK_HEIGHT));
  Animations[TankAnimationLeft] = animation;
  animation.clear();

  animation.push_back(CreateRect(0, 0, TANK_WIDTH, TANK_HEIGHT));
  animation.push_back(CreateRect(TANK_WIDTH, 0, TANK_WIDTH, TANK_HEIGHT));
  animation.push_back(CreateRect(2*TANK_WIDTH, 0, TANK_WIDTH, TANK_HEIGHT));
  Animations[TankAnimationUp] = animation;
  animation.clear();

  animation.push_back(CreateRect(0, 3*TANK_HEIGHT, TANK_WIDTH, TANK_HEIGHT));
  animation.push_back(CreateRect(TANK_WIDTH, 3*TANK_HEIGHT, TANK_WIDTH, TANK_HEIGHT));
  animation.push_back(CreateRect(2*TANK_WIDTH, 3*TANK_HEIGHT, TANK_WIDTH, TANK_HEIGHT));
  Animations[TankAnimationRight] = animation;
  animation.clear();

  animation.push_back(CreateRect(0, 2*TANK_HEIGHT, TANK_WIDTH, TANK_HEIGHT));
  animation.push_back(CreateRect(TANK_WIDTH, 2*TANK_HEIGHT, TANK_WIDTH, TANK_HEIGHT));
  animation.push_back(CreateRect(2*TANK_WIDTH, 2*TANK_HEIGHT, TANK_WIDTH, TANK_HEIGHT));
  Animations[TankAnimationDown] = animation;
  animation.clear();

  animation.push_back(CreateRect(0, 0, EXPLOSION_WIDTH, EXPLOSION_HEIGHT));
  animation.push_back(CreateRect(EXPLOSION_WIDTH, 0, EXPLOSION_WIDTH, EXPLOSION_HEIGHT));
  animation.push_back(CreateRect(2*EXPLOSION_WIDTH, 0, EXPLOSION_WIDTH, EXPLOSION_HEIGHT));
  Animations[ExplosionAnimation] = animation;
  animation.clear();

  animation.push_back(CreateRect(0, 0, EXPLOSION_TANK_WIDTH, EXPLOSION_TANK_HEIGHT));
  animation.push_back(CreateRect(EXPLOSION_TANK_WIDTH, 0, EXPLOSION_TANK_WIDTH, EXPLOSION_TANK_HEIGHT));
  animation.push_back(CreateRect(2*EXPLOSION_TANK_WIDTH, 0, EXPLOSION_TANK_WIDTH, EXPLOSION_TANK_HEIGHT));
  Animations[ExplosionTankAnimation] = animation;
  animation.clear();
}



SDL_Rect
Tanks::
Resources::
IMGSplitter::
CreateRect(int argX, int argY, int argW, int argH)
{
  SDL_Rect rect = *(new SDL_Rect());
  rect.x = argX;
  rect.y = argY;
  rect.w = argW;
  rect.h = argH;
  return rect;
}

